'''
driver.execute_script('js代码')
'''
from selenium import webdriver
import time

driver = webdriver.Chrome()
driver.get(url='https://search.jd.com/Search?keyword=%E8%B5%B5%E4%B8%BD%E9%A2%96&enc=utf-8&wq=%E8%B5%B5%E4%B8%BD%E9%A2%96&pvid=f71e6872505a41f585f7061ce99e3e4c')

# 执行js脚本
driver.execute_script(
    'window.scrollTo(0,document.body.scrollHeight)'
)
# 休眠，给页面元素加载预留时间
time.sleep(3)

# 提取数据
li_list = driver.find_elements_by_class_name("gl-item")
for li in li_list:
    item = {}
    item['title'] = li.find_element_by_xpath('.//div[@class="p-name p-name-type-2"]/a').text
    print(item)

# driver.quit()















